Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

Fact.setValue   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 4
loc 4
rs 10
1 View Code Duplication
var GedcomX = require('../'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    utils = require('../utils');
3
4
/**
5
 * A fact for a person or relationship.
6
 * 
7
 * @constructor
8
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
9
 */
10
var Fact = function(json){
11
  
12
  // Protect against forgetting the new keyword when calling the constructor
13
  if(!(this instanceof Fact)){
14
    return new Fact(json);
15
  }
16
  
17
  // If the given object is already an instance then just return it. DON'T copy it.
18
  if(Fact.isInstance(json)){
19
    return json;
20
  }
21
  
22
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
23
};
24
25
Fact.prototype = Object.create(GedcomX.Conclusion.prototype);
26
27
Fact._gedxClass = Fact.prototype._gedxClass = 'GedcomX.Fact';
28
29
Fact.jsonProps = [
30
  'type',
31
  'date',
32
  'place',
33
  'value',
34
  'qualifiers'
35
];
36
37
/**
38
 * Check whether the given object is an instance of this class.
39
 * 
40
 * @param {Object} obj
41
 * @returns {Boolean}
42
 */
43
Fact.isInstance = function(obj){
44
  return utils.isInstance(obj, this._gedxClass);
45
};
46
47
/**
48
 * Initialize from JSON
49
 * 
50
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
51
 * @return {Fact} this
52
 */
53
Fact.prototype.init = function(json){
54
  
55
  GedcomX.Conclusion.prototype.init.call(this, json);
56
  
57
  if(json){
58
    this.setType(json.type);
59
    this.setDate(json.date);
60
    this.setPlace(json.place);
61
    this.setValue(json.value);
62
    this.setQualifiers(json.qualifiers);
63
  }
64
  return this;
65
};
66
67
/**
68
 * Get the fact type
69
 * 
70
 * @returns {String} type
71
 */
72
Fact.prototype.getType = function(){
73
  return this.type;
74
};
75
76
/**
77
 * Set the fact type
78
 * 
79
 * @param {String} type
80
 * @returns {Fact} This instance
81
 */
82
Fact.prototype.setType = function(type){
83
  this.type = type;
84
  return this;
85
};
86
87
/**
88
 * Get the date
89
 * 
90
 * @returns {Date} date
91
 */
92
Fact.prototype.getDate = function(){
93
  return this.date;
94
};
95
96
/**
97
 * Set the date
98
 * 
99
 * @param {Date|Object} date
100
 * @returns {Fact} This instance
101
 */
102
Fact.prototype.setDate = function(date){
103
  if(date){
104
    this.date = GedcomX.Date(date);
105
  }
106
  return this;
107
};
108
109
/**
110
 * Get the place reference
111
 * 
112
 * @returns {PlaceReference}
113
 */
114
Fact.prototype.getPlace = function(){
115
  return this.place;
116
};
117
118
/**
119
 * Set the place reference
120
 *
121
 * @param {PlaceReference|Object} place
122
 * @returns {Fact} This instance
123
 */
124
Fact.prototype.setPlace = function(place){
125
  if(place){
126
    this.place = GedcomX.PlaceReference(place);
127
  }
128
  return this;
129
};
130
131
/**
132
 * Get the value
133
 * 
134
 * @returns {String}
135
 */
136
Fact.prototype.getValue = function(){
137
  return this.value;
138
};
139
140
/**
141
 * Set the value
142
 * 
143
 * @param {String} value
144
 * @returns {Fact} This instance
145
 */
146
Fact.prototype.setValue = function(value){
147
  this.value = value;
148
  return this;
149
};
150
151
/**
152
 * Get qualifiers
153
 * 
154
 * @return {Qualifer[]}
155
 */
156
Fact.prototype.getQualifiers = function(){
157
  return this.qualifiers || [];
158
};
159
160
/**
161
 * Set the qualifiers
162
 * 
163
 * @param {Qualifer[]|Object[]} qualifiers
164
 * @returns {Fact} This instance
165
 */
166
Fact.prototype.setQualifiers = function(qualifiers){
167
  return this._setArray(qualifiers, 'qualifiers', 'addQualifier');
168
};
169
170
/**
171
 * Add a qualifier
172
 * 
173
 * @param {Qualifier|Object} qualifier
174
 * @returns {Fact} This instance
175
 */
176
Fact.prototype.addQualifier = function(qualifier){
177
  return this._arrayPush(qualifier, 'qualifiers', GedcomX.Qualifier);
178
};
179
180
/**
181
 * Export the object as JSON
182
 * 
183
 * @return {Object} JSON object
184
 */
185
Fact.prototype.toJSON = function(){
186
  return this._toJSON(GedcomX.Conclusion, Fact.jsonProps);
187
};
188
189
module.exports = Fact;